<template>
	<view>
		<view class="cu-custom" :style="[{height:CustomBar + 'px'},customStyle]">
			<view class="cu-bar fixed" :style="style" :class="[bgImage!=''?'none-bg text-white bg-img':'',bgColorClass]">
				<view class="action" @tap="BackPage" v-if="isBack" style="white-space: nowrap;">
					<text :class="isWhite?'white':''" class="cuIcon-back " style="font-size: 42rpx;" v-if="isBackIcon"></text>
					<slot name="backText"></slot>
				</view>
				<view class="left" v-if="isLeft">
					<slot name="left"></slot>
				</view>
				<view class="content" :style="[{top:StatusBar + 'px'}]">
					<slot name="content"></slot>
				</view>
				<view class="right">
					<slot name="right"></slot>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import util from '@/common/util'
	export default {
		data() {
			return {
				StatusBar: this.StatusBar,
				CustomBar: this.CustomBar
			};
		},
		name: 'cu-custom',
		computed: {
			tabList() {
				var list = JSON.parse(JSON.stringify(this.$store.state.tabBars))
				let newList = list.map(item=>{
					return item.path
				})
				return newList
			},
			style() {
				var StatusBar= this.StatusBar;
				var CustomBar= this.CustomBar;
				var bgImage = this.bgImage;
				var style = `height:${CustomBar}px;padding-top:${StatusBar}px;background:${this.bgColor || ''};`;
				if (this.bgImage) {
					style = `${style}background-image:url(${bgImage});`;
				}
				return style
			}
		},
		props: {
			customStyle:{
				
			},
			isWhite:{
				type: [Boolean, String],
				default: false
			},
			bgColor: {
				type: String,
				default: ''
			},
			bgColorClass: {
				type: String,
				default: ''
			},
			isBackIcon:{
				type: [Boolean, String],
				default: true
			},
			isBack: {
				type: [Boolean, String],
				default: false
			},
			isLeft: {
				type: [Boolean, String],
				default: false
			},
			bgImage: {
				type: String,
				default: ''
			},
		},
		mounted() {
		
		},
		methods: {
			BackPage() {
				let pages = getCurrentPages();
				let current = pages[pages.length - 1]
				if(pages.length === 1 && this.tabList.includes(current.$page.fullPath)){
					uni.$emit('tabToNavOn')
					return
				}
				
				util.toBack()
			}
		}
	}
</script>

<style>
	.content {
		font-weight: 600;
	}
	
	.head-bg{
		background: #57c89d;
	}
	.code-bg{
		background: #fff4f3;
	}
	.head-bg-gray{
		background: #f8f8f8;
	}
	.white{
		color: #fff;
	}
	.bgColor{
		background: #fff;
	}
	.bgtran{
		background: transparent;
	}
	.index-head-bg{
		background: #ff3839;
	}
	.cu-custom .right {
		position: relative;
		z-index: 9;
		width: 100%;
	}
	.blueHead{
		background: linear-gradient(90deg, #ff7472 0%, #ff7472 100%), #ff1403;
	}
	.FFF4F3{
		background: #FFF4F3;
	}
</style>
